#ifndef THINK_THINK_TEMPLATE_DRIVER_FILE_H
#define THINK_THINK_TEMPLATE_DRIVER_FILE_H

static char* think_template_driver_file =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\template\\driver;\n"
	"\n"
	"use think\\Exception;\n"
	"\n"
	"class File\n"
	"{\n"
	"    protected $cacheFile;\n"
	"\n"
	"    /**\n"
	"     * 写入编译缓存\n"
	"     * @param string $cacheFile 缓存的文件名\n"
	"     * @param string $content 缓存的内容\n"
	"     * @return void|array\n"
	"     */\n"
	"    public function write($cacheFile, $content)\n"
	"    {\n"
	"        // 检测模板目录\n"
	"        $dir = dirname($cacheFile);\n"
	"        if (!is_dir($dir)) {\n"
	"            mkdir($dir, 0755, true);\n"
	"        }\n"
	"        // 生成模板缓存文件\n"
	"        if (false === file_put_contents($cacheFile, $content)) {\n"
	"            throw new Exception(\'cache write error:\' . $cacheFile, 11602);\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 读取编译编译\n"
	"     * @param string  $cacheFile 缓存的文件名\n"
	"     * @param array   $vars 变量数组\n"
	"     * @return void\n"
	"     */\n"
	"    public function read($cacheFile, $vars = [])\n"
	"    {\n"
	"        $this->cacheFile = $cacheFile;\n"
	"        if (!empty($vars) && is_array($vars)) {\n"
	"            // 模板阵列变量分解成为独立变量\n"
	"            extract($vars, EXTR_OVERWRITE);\n"
	"        }\n"
	"        //载入模版缓存文件\n"
	"        include $this->cacheFile;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 检查编译缓存是否有效\n"
	"     * @param string  $cacheFile 缓存的文件名\n"
	"     * @param int     $cacheTime 缓存时间\n"
	"     * @return boolean\n"
	"     */\n"
	"    public function check($cacheFile, $cacheTime)\n"
	"    {\n"
	"        // 缓存文件不存在, 直接返回false\n"
	"        if (!file_exists($cacheFile)) {\n"
	"            return false;\n"
	"        }\n"
	"        if (0 != $cacheTime && $_SERVER[\'REQUEST_TIME\'] > filemtime($cacheFile) + $cacheTime) {\n"
	"            // 缓存是否在有效期\n"
	"            return false;\n"
	"        }\n"
	"        return true;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif